package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbApproveProcess;
import com.sailfish.springbootdemo.pojo.db2.PcbPermissionConfig;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbPermissionConfigDao {
    @Results(id = "pcbPermissionConfigResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "permission_type", property = "permissionType", jdbcType = JdbcType.INTEGER),
            @Result(column = "permission_type_name", property = "permissionTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_user_id", property = "approveUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "approve_user_name", property = "approveUserName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER)
    })

    @Select("<script> " +
            "select *" +
            "from " + DB2TableName.PCB_PERMISSION_CONFIG +
            " where id = #{id}" +
            "</script>")
    PcbPermissionConfig getById(@Param("id") Integer id);

    @Select("<script> " +
            "select *" +
            "from " + DB2TableName.PCB_PERMISSION_CONFIG +
            "<where> " +
            "<if test='permissionType != null'>" +
            " and permission_type = #{permissionType}" +
            "</if>" +
            "</where> " +
            "</script>")
    @ResultMap(value = "pcbPermissionConfigResultMap")
    List<PcbPermissionConfig> getByLimit(PcbPermissionConfig param);

    @Insert("insert into " + DB2TableName.PCB_PERMISSION_CONFIG +
            "(permission_type, permission_type_name, approve_user_id, approve_user_name, remark, create_user, create_time, update_user, update_time, status, sort)" +
            "values (#{permissionType}, #{permissionTypeName}, #{approveUserId}, #{approveUserName}, #{remark}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime}, #{status}, #{sort})")
    Integer insert(PcbPermissionConfig param);

    @Update("<script>" +
            "update " + DB2TableName.PCB_PERMISSION_CONFIG +
            "<set>" +
            "<if test='permissionType != null'>" +
            "permission_type = #{permissionType}," +
            "</if>" +
            "<if test='permissionTypeName != null'>" +
            "permission_type_name = #{permissionTypeName}," +
            "</if>" +
            "<if test='approveUserId != null'>" +
            "approve_user_id = #{approveUserId}," +
            "</if>" +
            "<if test='approveUserName != null'>" +
            "approve_user_name = #{approveUserName}," +
            "</if>" +
            "<if test='remark != null and remark != \"\"'>" +
            "remark = #{remark}," +
            "</if>" +
            "<if test='sort != null'>" +
            "sort = #{sort}," +
            "</if>" +
            "<if test='status != null'>" +
            "status = #{status}," +
            "</if>" +
            "<if test='createTime != null'>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            "update_time = #{updateTime}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "create_user = #{createUser}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "update_user = #{updateUser}," +
            "</if>" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    Integer update(PcbPermissionConfig param);
}
